#include "StdAfx.h"
#include "Digit.h"
#include "Scaler.h"
#include "Desired.h"

#undef min
#undef max
namespace MnistDigit
{
	Digit::Digit(const unsigned char digitValue
		, const std::vector<unsigned char>& data)
		: m_desiredClass(digitValue)
		, m_class(Desired::GetClassCount())
		, m_data(data)
	{
		m_input.resize(m_data.size()+1);//+1 for bias
		std::transform(m_data.begin(), m_data.end()
			, m_input.begin()
			, Scaler(std::numeric_limits<unsigned char>::min()
			, std::numeric_limits<unsigned char>::max()
			, -1
			, 1)
			);
		m_input.back()=1.0;//Bias value
	}

	Digit::~Digit(void)
	{
	}

	const std::vector<double>& Digit::GetInput() const
	{
		return m_input;
	}

	const std::vector<double>& Digit::GetDesired() const
	{
		return Desired::GetDesired(m_desiredClass);
	}

	void Digit::SetOutput(const std::vector<double>& output)
	{
		m_output=output;
		m_class = Desired::FindClass(output);
	}

	bool Digit::IsClassified() const
	{
		return m_class==m_desiredClass;
	}

}